#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
int ind[N];
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int seq[N], num;
void topo_sort() {
  queue<int> q;
  rep(i, 1, n) if (!ind[i]) q.push(i);
  while (q.size()) {
    int u = q.front();
    q.pop();
    seq[++num] = u;
    for (int i = head[u]; i; i = Next[i]) {
      int v = ver[i];
      if (!--ind[v]) q.push(v);
    }
  }
}
double dp[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w);
    ind[v]++;
  }
  topo_sort();
  per(i, n - 1, 1) {
    int u = seq[i];
    double sum = 0;
    int cnt = 0;
    for (int i = head[u]; i; i = Next[i]) {
      int v = ver[i];
      int w = W[i];
      sum += w + dp[v];
      cnt++;
    }
    dp[u] = sum / cnt;
  }
  cout << fixed << setprecision(2) << dp[1];
  return 0;
}